import { Inject, Injectable } from '@nestjs/common';
import { create } from 'svg-captcha';
import Redis from 'ioredis';
import { RedisKeys } from '@/common/enum/RedisKeys';
@Injectable()
export class ManagerService {
  @Inject('REDIS')
  private readonly redis: Redis;


  // 验证码功能
  createCaptch(codeId: string) {
    const { text, data } = create({
      size: 4, // 几个验证码
      width: 120,
      height: 36,
      fontSize: 50,
      ignoreChars: 'i1l0oaqg' // 忽略字符 这些字符因为高度的问题截取不好识别
    });
    console.log('验证码', text);

    // redis 持久化 - 设置验证码 为 1 分钟过期
    this.redis.set(`${RedisKeys.LOGIN_CODE}:${codeId}`, text, 'EX', 60*1)

    return data;
  }

  // 临时 - 验证jwt 接口
  getDashboard(){
    return 'hello world'
  }
}
